﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Repo7.BusinessLogic.Utils
{
    /// <summary>
    /// Repo7 Application Configuration Section
    /// </summary>
    internal class Repo7Configurations : ConfigurationSection
    {
        /// <summary>
        /// Command End Point - default is 127.0.0.1:45679
        /// </summary>
        [ConfigurationProperty("Repo7Local", IsRequired = true)]
        public Repo7Local Local
        {
            get { return (Repo7Local)this["Repo7Local"]; }
        }

        /// <summary>
        /// Repository Peer List
        /// </summary>
        [ConfigurationProperty("Repo7Peers", IsRequired = false)]
        public Repo7Peers Peers
        {
            get { return (Repo7Peers)this["Repo7Peers"]; }
        }
    }

    /// <summary>
    /// Repository Peer List 
    /// </summary>
    [ConfigurationCollection(typeof(Repo7Peer), AddItemName = "Peer", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    internal class Repo7Peers : ConfigurationElementCollection
    {

        protected override ConfigurationElement CreateNewElement()
        {
            return new Repo7Peer();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            return ((Repo7Peer)element).Name;
        }

    }

    /// <summary>
    /// Repository Peer
    /// </summary>
    internal class Repo7Peer : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            get
            {
                return (string)base["name"];
            }
        }

        /// <summary>
        /// Local File Transfer End Point - default is 127.0.0.1:45678
        /// </summary>
        [ConfigurationProperty("fileTransferEndPoint", DefaultValue = "127.0.0.1:45678", IsRequired = false)]
        public string FileTransferEndPoint
        {
            get { return (string)this["fileTransferEndPoint"]; }
            set { this["fileTransferEndPoint"] = value; }
        }

        /// <summary>
        /// Command End Point - default is 127.0.0.1:45679
        /// </summary>
        [ConfigurationProperty("commandEndPoint", DefaultValue = "127.0.0.1:45679", IsRequired = false)]
        public string CommandEndPoint
        {
            get { return (string)this["commandEndPoint"]; }
            set { this["commandEndPoint"] = value; }
        }

    }

    /// <summary>
    /// Repository Local configuration
    /// </summary>
    internal class Repo7Local : ConfigurationElement
    {
        /// <summary>
        /// Local File Transfer End Point - default is 127.0.0.1:45678
        /// </summary>
        [ConfigurationProperty("repoDirectoryPath", IsRequired = true)]
        public string RepoDirectoryPath
        {
            get { return (string)this["repoDirectoryPath"]; }
            set { this["repoDirectoryPath"] = value; }
        }

        /// <summary>
        /// Local File Transfer End Point - default is 127.0.0.1:45678
        /// </summary>
        [ConfigurationProperty("fileTransferEndPoint", DefaultValue = "127.0.0.1:45678", IsRequired = false)]
        public string FileTransferEndPoint
        {
            get { return (string)this["fileTransferEndPoint"]; }
            set { this["fileTransferEndPoint"] = value; }
        }

        /// <summary>
        /// Command End Point - default is 127.0.0.1:45679
        /// </summary>
        [ConfigurationProperty("commandEndPoint", DefaultValue = "127.0.0.1:45679", IsRequired = false)]
        public string CommandEndPoint
        {
            get { return (string)this["commandEndPoint"]; }
            set { this["commandEndPoint"] = value; }
        }
    }
}
